package com.apkcore.flowlib.flow

import androidx.lifecycle.LifecycleOwner

/**
 * @author chanehao
 * @date 2023/03/08
 * @apiNote
 */
abstract class IFlowManager<T> {
    abstract fun addInterceptors(): ArrayList<Interceptor<*>>

    private var controller: InterceptorController<T>? = null

    fun init(lifecycleOwner: LifecycleOwner): IFlowManager<T> {
        controller = InterceptorController(lifecycleOwner)
        val addInterceptors = addInterceptors()
        addInterceptors.forEach {
            controller?.addInterceptor(it)
        }
        return this
    }

    fun startFlow(request: Request, delayMill: Long = 500) {
        controller?.start(request, delayMill)
    }

    fun pauseFlow() {
        controller?.pause()
    }

    fun resumeFlow() {
        controller?.resume()
    }

    open fun stopFlow() {
        release()
        controller?.stop()
    }

    open fun release() {}
}